<template>
  <div class="view-container">

    <table-search-view ref="orderView" :search-items="searchItems" :table-items="tableItems" :search-function="search">
      <template slot="action" slot-scope="scope">
        <action-buyout-info :action="true" :scope="scope" @success="actionSuccess"></action-buyout-info>
        <action-info :scope="scope"></action-info>
      </template>
    </table-search-view>

  </div>
</template>

<script>
  import TableSearchView from '@/components/TableSearchView';

  import actionOrderInfo from './components/actionOrderInfo.vue';
  import actionBuyoutInfo from './components/actionBuyoutInfo.vue';
  import {getOrderBuyoutList} from '@/api/order';

  export default {
    name: 'buyoutApply', /*买断申请*/
    components: {
      'table-search-view':TableSearchView,
      'action-info':actionOrderInfo,
      'action-buyout-info':actionBuyoutInfo,
    },
    data ()
    {
      return {
        searchItems: [
          {
            label: '商品名称',
            type: 'autocomplete',
            placeholder:'请输入商品名称',
            model:'goodsName',
          },
          {
            label: '当前订单到期时间',
            type: 'datetimerange',
            placeholder:'请选择当前订单到期时间',
            model:'timeRange',
          },
          {
            label: '买断申请单编号',
            type: 'input',
            placeholder:'请输入买断申请单编号',
            model:'buyoutNumber',
          },
          {
            label: '下单用户',
            type: 'input',
            placeholder:'请输入下单用户',
            model:'userName',
          },
          {
            label: '订单编号',
            type: 'input',
            placeholder:'请输入订单编号',
            model:'orderNumber',
          },
        ],
        tableItems:[
          {
            label:'买断申请单编号',
            prop:'buyoutNumber',
            width:'180px;',
          },
          {
            label:'当前订单编号',
            prop:'orderNumber',
            width:'180px;',
          },
          {
            label:'商品名称',
            prop:'goodsName',
            width:'180px;',
            sortable:true,
          },
          {
            label:'下单用户',
            prop:'userName',
            width:'180px;',
            sortable:true,
          },
          {
            label:'当前订单到期时间',
            prop:'leaseExpireTime',
            width:'160px;',
            formatter:'parseTime',
            sortable:true,
          },
          {
            label:'结清时间',
            prop:'clearanceTime',
            width:'160px;',
            formatter:'parseTime',
            sortable:true,
          },
          {
            label:'当前订单状态',
            prop:'stateStr',
            width:'160px;',
            sortable:true,
          },
          {
            type:'scope',
            label:'操作',
            slot:'action',
            width:'200px;',
          },
          {

          }
        ],
      }
    },
    methods: {
      search(data)
      {
        data.tab='check';
        return getOrderBuyoutList(data);

        /*return new Promise(resolve => {
          let resp = {data:{total:10, list:[
            {
              "id": 1,
              "buyoutNumber": "XZ5467945458787",
              "orderNumber": "201712652367846854",
              "goodsName": "IphoneX",
              "userName": "17682311195",
              "leaseExpireTime": 1511932806661,
              "clearanceTime": 1511931748392,
              "status": "check",
              "stateStr": "租赁中"
            },
            {
              "id": 1,
              "buyoutNumber": "XZ5467945458787",
              "orderNumber": "201712652367846854",
              "goodsName": "IphoneX",
              "userName": "17682311195",
              "leaseExpireTime": 1511932830851,
              "clearanceTime": 1511932056742,
              "status": "check",
              "stateStr": "租赁中"
            },
            {
              "id": 1,
              "buyoutNumber": "XZ5467945458787",
              "orderNumber": "201712652367846854",
              "goodsName": "IphoneX",
              "userName": "17682311195",
              "leaseExpireTime": 1511930950750,
              "clearanceTime": 1511931478588,
              "status": "check",
              "stateStr": "租赁中"
            }
          ]}};

          resolve(resp);
        });*/
      },
      actionSuccess() //操作成功,调用search方法
      {
        this.$refs['orderView'].search();
      },
    }
  }
</script>
